import store from '@/store'

export default {
  inserted (el, binding) {
    const { value } = binding
    const permissions = store.state.user.permissions
    // 超级管理员
    if (permissions && permissions.includes('*:*:*')) return
    // 无权限码控制默认显示
    if (!value) return
    const permissionCodeList = Array.isArray(value) ? value : [value]
    if (permissionCodeList.length) {
      const hasPermission = permissions && permissions.some(r => permissionCodeList.includes(r))
      if (!hasPermission) {
        el.parentNode && el.parentNode.removeChild(el)
      }
    }
  }
}
